<?php
/**
 * Created by PhpStorm.
 * User: vanity
 * Date: 2018/1/3
 * Time: 16:22
 */
namespace Admin\Model;
use Think\Model\RelationModel;
class UserModel extends RelationModel
{
    protected $tableName='user';
    protected $patchValidate = true;
    protected $_validate = array(
        array('name','require','用户名不能为空',0),
        array('name','require','用户名已存在！',1,'unique',1),
        array('repassword','password','两次密码输入不一致',0,'confirm'), // 验证确认密码是否和密码一致
//        array('password','require','密码不能为空',1),
    );
    protected $_auto = array (
        array('password','md5',3,'function'),
        array('created_time','time',1,'function'), // 对update_time字段在添加的时候写入当前时间戳
        array('updated_time','time',2,'function'), // 对update_time字段在更新的时候写入当前时间戳
    );
    protected $_link = array(
        'role_user'=>array( //权限和权限角色关联表
            'mapping_type'=> self::HAS_ONE,
            'foreign_key'=>'user_id',
            'mapping_fields'=>'role_id',
            'as_fields'=>'role_id',
        )
    );
}
